package com.tamplus.cs.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateUtils {

	public static String getDateStr(Date date, String format) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.US);
			return dateFormat.format(date);
		}
	}

	public static Date createDate(String strDate, String format) {
		if(strDate == null || "".equals(strDate)) return null;
		
		SimpleDateFormat dFormat = new SimpleDateFormat(format, Locale.US);
		Date d = null;
		try {
			d = dFormat.parse(strDate);
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		return d;
	}

	public static void main(String[] args){
		Calendar cNow = Calendar.getInstance(Locale.US);
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(Calendar.YEAR, 2012);
		c.set(Calendar.MONTH, 0);
		c.set(Calendar.DATE, 1);
		
		System.out.println(cNow.compareTo(c));
	}

}
